﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ViCode_LeVi.Langs;
using System.ComponentModel;
using ViCode_LeVi.Controls.Charts;
using ViCode_LeVi.Controls.ControlsWin;
using ViCode_LeVi.Controls.Reports;
using ViCode_LeVi.Controls.Logs;
using ViCode_LeVi.Configs;
using System.Windows.Documents;
using dotnetCHARTING.WinForms;
using System.Windows.Media;

namespace ViCode_LeVi.Data
{
    [DataContract]
    public class ImageInfo : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
        [DataMember]
        public Byte[] Info
        { get; set; }
        [DataMember]
        string _Description;
        public string Description
        {
            get
            {
                return _Description;
            }

            set
            {
                if (_Description != value)
                {
                    _Description = value;
                    SendPropertyChanged("Description");
                }
            }
        }
    }
    [DataContract]
    public class ProjectData : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
        private static ProjectData _Intance = new ProjectData();
        public static ProjectData Intance
        {
            get
            {
                if (_Intance == null)
                    _Intance = new ProjectData();
                if (_Intance.StartedDate_Date < DateTime.Now.AddYears(-100))
                    _Intance.StartedDate_Date = DateTime.Now;
                #region ImageInfos
                if (_Intance.ImageInfos == null)
                    _Intance.ImageInfos = new ImageInfo[4];
                if (_Intance.ImageInfos.Length < 4)
                {
                    List<ImageInfo> list = new List<ImageInfo>(_Intance.ImageInfos);
                    while (list.Count < 4)
                    {
                        list.Add(new ImageInfo());
                        if (list.Count > 4)
                            break;
                    }
                    _Intance.ImageInfos = list.ToArray();
                }
                for (int i = 0; i < _Intance.ImageInfos.Length; i++)
                    if (_Intance.ImageInfos[i] == null)
                        _Intance.ImageInfos[i] = new ImageInfo();
                #endregion

                return _Intance;
            }
            set
            {
                _Intance = value;
                //if (_Intance != null)
                //    _Intance.RaiseAllProperties();
            }
        }
        private static string _FileSave;
        public static string FileSave
        {
            get { return _FileSave; }
            set
            {
                if (value != _FileSave)
                {
                    _FileSave = value;
                    if (Action_FileSave_Changed != null)
                    {
                        string sTitle = ControlTextInfo.Intance.Application_Title + " - "
                            + (string.IsNullOrEmpty(_FileSave) ? "new project" : _FileSave);
                        Action_FileSave_Changed(sTitle);
                    }
                }
            }
        }
        public static Action<string> Action_FileSave_Changed;

        #region UI Project Info
        #region UIText_CompanyName
        [DataMember]
        string _UIText_CompanyName = string.Empty;
        public string UIText_CompanyName
        {
            get
            {
                if (string.IsNullOrEmpty(_UIText_CompanyName))
                    _UIText_CompanyName = "Company:";
                return _UIText_CompanyName;
            }
            set
            {
                if (_UIText_CompanyName != value)
                {
                    _UIText_CompanyName = value;
                    SendPropertyChanged("UIText_CompanyName");
                }
            }
        }
        #endregion

        #region UIText_Name
        [DataMember]
        string _UIText_Name = string.Empty;
        public string UIText_Name
        {
            get
            {
                if (string.IsNullOrEmpty(_UIText_Name))
                    _UIText_Name = "Project's name:";
                return _UIText_Name;
            }
            set
            {
                if (_UIText_Name != value)
                {
                    _UIText_Name = value;
                    SendPropertyChanged("UIText_Name");
                }
            }
        }
        #endregion

        #region UIText_Author
        [DataMember]
        string _UIText_Author = string.Empty;
        public string UIText_Author
        {
            get
            {
                if (string.IsNullOrEmpty(_UIText_Author))
                    _UIText_Author = "Creator";
                return _UIText_Author;
            }
            set
            {
                if (_UIText_Author != value)
                {
                    _UIText_Author = value;
                    SendPropertyChanged("UIText_Author");
                }
            }
        }
        #endregion

        #region UIText_Comment
        [DataMember]
        string _UIText_Comment = string.Empty;
        public string UIText_Comment
        {
            get
            {
                if (string.IsNullOrEmpty(_UIText_Comment))
                    _UIText_Comment = "Commentator";
                return _UIText_Comment;
            }
            set
            {
                if (_UIText_Comment != value)
                {
                    _UIText_Comment = value;
                    SendPropertyChanged("UIText_Comment");
                }
            }
        }
        #endregion

        #region UIText_StartedDate
        [DataMember]
        string _UIText_StartedDate = string.Empty;
        public string UIText_StartedDate
        {
            get
            {
                if (string.IsNullOrEmpty(_UIText_StartedDate))
                    _UIText_StartedDate = "Start Date";
                return _UIText_StartedDate;
            }
            set
            {
                if (_UIText_StartedDate != value)
                {
                    _UIText_StartedDate = value;
                    SendPropertyChanged("UIText_StartedDate");
                }
            }
        }
        #endregion
        #endregion

        [DataMember]
        public string CompanyName { get; set; }
        [DataMember]
        public string Name { get; set; }

        public string FileName { get { return FileSave; } }
        [DataMember]
        public string Author { get; set; }
        [DataMember]
        public string Comment { get; set; }

        [Obsolete("khong su dung. 1 phut lo lam")]
        [DataMember]
        public string StartedDate { get; set; }

        [DataMember]
        public DateTime StartedDate_Date { get; set; }

        public void SendProperty_ProjectInfo()
        {
            SendPropertyChanged("CompanyName");
            SendPropertyChanged("Name");
            SendPropertyChanged("Author");
            SendPropertyChanged("Comment");
            SendPropertyChanged("StartedDate");
        }
        [DataMember]
        public RootData[] Periods;
        [DataMember]
        public int Period_Index;
        [DataMember]
        public ImageInfo[] ImageInfos;

        #region TextBox Format
        [DataMember]
        public VMTextBoxFormatInfo VMTextBoxFormatInfo_Intance
        {
            get { return VMTextBoxFormatInfo.Intance; }
            set { VMTextBoxFormatInfo.Intance = value; }
        }

        #endregion

        #region Static Enum
        [DataMember]
        public Static_E_Risk_Impact Static_E_Risk_Impact_Intance
        {
            get { return Static_E_Risk_Impact.Instance; }
            set { Static_E_Risk_Impact.Instance = value; }
        }
        //Static_E_Risk_Probability
        [DataMember]
        public Static_E_Risk_Probability Static_E_Risk_Probability_Intance
        {
            get { return Static_E_Risk_Probability.Instance; }
            set { Static_E_Risk_Probability.Instance = value; }
        }
        #endregion
        public RootData Period
        {
            get
            {
                if (Periods == null || Periods.Length == 0)
                    return null;
                if (Period_Index < 0)
                    Period_Index = 0;
                if (Period_Index > Periods.Length - 1)
                    Period_Index = Periods.Length - 1;
                var period = Periods[Period_Index];
                CheckAndRefinePeriod(period);
                return period;
            }
        }
        private void CheckAndRefinePeriod(RootData _period)
        {
            if (_period != null)
            {
                #region 10
                if (_period.Steps.Length < 12)
                {
                    List<StepInfo> list = new List<StepInfo>();
                    list.AddRange(_period.Steps);

                    //FINANCIAL
                    while (list.Count() < 10)
                    {
                        StepInfo step10 = new StepInfo();
                        step10.ShortName = "FINANCIAL";
                        step10.FullName = "FINANCIAL";
                        step10.Result = StepResult.Create_StepResult_None();
                        step10.BalanceAndOthers = new Step_BalanceAndOthers();
                        //step10.
                        list.Add(step10);
                    }
                    //BackGround
                    while (list.Count() < 11)
                    {
                        StepInfo step11 = new StepInfo();
                        step11.ShortName = "Home";
                        step11.FullName = "Home";
                        //step11.
                        list.Add(step11);
                    }
                    //Risk
                    while (list.Count() < 12)
                    {
                        StepInfo step12 = new StepInfo();
                        step12.ShortName = "RISK";
                        step12.FullName = "RISK MANAGEMENT";
                        step12.RiskManagement = new Step_RiskManagement();
                        //step12.
                        list.Add(step12);
                    }
                    //Budget
                    while (list.Count() < 13)
                    {
                        StepInfo step13 = new StepInfo();
                        step13.ShortName = "BUDGET";
                        step13.FullName = "BUDGET MANAGEMENT";
                        step13.Budget = new Step_Budget();
                        //step13.
                        list.Add(step13);
                    }
                    _period.Steps = list.ToArray();
                }
                if (_period.Steps.Length >= 10)
                {
                    var step10 = _period.Steps[9];
                    if (step10 == null)
                    {
                        step10 = new StepInfo();
                        step10.ShortName = "FINANCIAL";
                        step10.FullName = "FINANCIAL";
                        step10.Result = StepResult.Create_StepResult_None();
                    }
                    if (step10.BalanceAndOthers == null)
                    {
                        step10.BalanceAndOthers = new Step_BalanceAndOthers();
                    }
                    if (step10.BalanceAndOthers != null)
                        step10.BalanceAndOthers.CheckAllPropertiesAndRefine();
                    if (step10.Result == null)
                    {
                        step10.Result = StepResult.Create_StepResult_None();
                    }
                }
                #endregion
            }
        }
        public RootData CurrentPeriod
        {
            get
            {
                var _period = Period;
                CheckAndRefinePeriod(_period);
                return _period;
            }
        }
        #region ControlTextInfoInData
        [DataMember]
        ControlTextInfoInData _ControlTextInfoInData;
        public ControlTextInfoInData ControlTextInfoInData
        {
            get
            {
                if (_ControlTextInfoInData == null)
                {
                    _ControlTextInfoInData = new ControlTextInfoInData();
                }
                return _ControlTextInfoInData;
            }
            set
            {
                _ControlTextInfoInData = value;
                if (_ControlTextInfoInData != null)
                {
                    _ControlTextInfoInData = value;
                }
            }
        }
        #endregion
        public void Save()
        {
            if (string.IsNullOrEmpty(FileName))
            {
                string sPath = FileFolder.ChooseFileDialog.ChooseFile4SaveWithTitle("File (*.scg)|*.scg", ControlTextInfo.Intance.Dialog_File4Saving_Title);
                if (!string.IsNullOrEmpty(sPath))
                {
                    FileSave = sPath;
                }
                else
                    return;
            }
            //Save
            try
            {
                if (System.IO.File.Exists(FileName))
                    System.IO.File.Delete(FileName);
            }
            catch { }
            XMLDataSerializer.XMLData<ProjectData>.SaveEntity(FileName, Intance);
        }

        public void SaveAs()
        {
            string sPath = FileFolder.ChooseFileDialog.ChooseFile4SaveWithTitle("scg File (*.scg)|*.scg", ControlTextInfo.Intance.Dialog_File4Saving_Title);
            if (!string.IsNullOrEmpty(sPath))
            {
                FileSave = sPath;
                Save();
            }
        }
        public static ProjectData GetFromTemplate(string template)
        {
            string sPath = System.IO.Path.Combine(FileFolder.AppInfo.AppDirectory, "Templates/" + template);
            return GetFromFile(sPath);
        }
        public static ProjectData GetFromFile(string sPath)
        {
            if (!string.IsNullOrEmpty(sPath) && System.IO.File.Exists(sPath))
            {
                ProjectData data = XMLDataSerializer.XMLData<ProjectData>.GetEntity(sPath);
                if (data == null)
                {
                    RootData root = GetFromFile_Temp(sPath);
                    if (root != null)
                    {
                        data = new ProjectData();
                        data.Periods = new RootData[] { root };
                    }
                }
                return data;
            }
            return null;
        }

        public static void OPenAndSetRootData()
        {
            string sPath = FileFolder.ChooseFileDialog.ChooseFile("scg File (*.scg)|*.scg", ControlTextInfo.Intance.Dialog_File4Saving_Title);
            if (!string.IsNullOrEmpty(sPath))
            {
                var data = GetFromFile(sPath);
                if (data != null)
                {
                    FileSave = sPath;
                    ProjectData.Intance = data;
                }
            }
        }

        public static RootData GetFromFile_Temp(string sPath)
        {
            if (!string.IsNullOrEmpty(sPath) && System.IO.File.Exists(sPath))
            {
                var data = XMLDataSerializer.XMLData<RootData>.GetEntity(sPath);
                return data;
            }
            return null;
        }
        public static ProjectData CreateDefaultRootData()
        {
            ProjectData dataFromFile = ProjectData.GetFromTemplate("en.scg");
            return dataFromFile;
        }
    }

    [DataContract]
    public class RootData : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region From BTB
        /// <summary>
        /// Co nhieu Period. moi cai co 1 ID
        /// </summary>
        public string ID { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        #endregion

        #region End Report
        public AmpelType BankAmpelStep1 { get; set; }
        public string BankCommentStep1
        {
            get
            {
                if (this.Steps.Length > 0 && this.Steps[0].Result != null)
                    return this.Steps[0].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep2 { get; set; }
        public string BankCommentStep2
        {
            get
            {
                if (this.Steps.Length > 1 && this.Steps[1].Result != null)
                    return this.Steps[1].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep3 { get; set; }
        public string BankCommentStep3
        {
            get
            {
                if (this.Steps.Length > 2 && this.Steps[2].Result != null)
                    return this.Steps[2].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep4 { get; set; }
        public string BankCommentStep4
        {
            get
            {
                if (this.Steps.Length > 3 && this.Steps[3].Result != null)
                    return this.Steps[3].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep5 { get; set; }
        public string BankCommentStep5
        {
            get
            {
                if (this.Steps.Length > 4 && this.Steps[4].Result != null)
                    return this.Steps[4].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep6 { get; set; }
        public string BankCommentStep6
        {
            get
            {
                if (this.Steps.Length > 5 && this.Steps[5].Result != null)
                    return this.Steps[5].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep7 { get; set; }
        public string BankCommentStep7
        {
            get
            {
                if (this.Steps.Length > 6 && this.Steps[6].Result != null)
                    return this.Steps[6].Result.Note;
                return string.Empty;
            }
        }

        /// <summary>
        /// Tab nay la cai moi, ko giong phan mem cu, nen cho nay ko co xuat report
        /// ---> thu tu la 8 thay vi 7
        /// </summary>
        public AmpelType BankAmpelStep8 { get; set; }
        public string BankCommentStep8
        {
            get
            {
                if (this.Steps.Length > 8 && this.Steps[8].Result != null)
                    return this.Steps[8].Result.Note;
                return string.Empty;
            }
        }

        public AmpelType BankAmpelStep9 { get; set; }
        public string BankCommentStep9
        {
            get
            {
                if (this.Steps.Length > 8 && this.Steps[8].Result != null)
                    return this.Steps[8].Result.Note;
                return string.Empty;
            }
        }

        //Todo: kiem tra gia tri
        public string InterpretationImportanceChart { get; set; }
        public string InterpretationQQSBarChartHK { get; set; }
        public string InterpretationQQSBarChartSK { get; set; }
        public string InterpretationQQSBarChartBK { get; set; }
        public string InterpretationPotentialPortfolio
        {
            get
            {
                if (RootData.Intance != null
                    && RootData.Intance.Steps != null
                    && RootData.Intance.Steps.Length > 3
                    && RootData.Intance.Steps[5] != null
                    && RootData.Intance.Steps[5].Analysis != null)
                    return RootData.Intance.Steps[5].Analysis.Interpretation3;
                return string.Empty;
            }
            set
            { }
        }


        public ContentSelectionType2 ContentsBTBKMU { get; set; }
        public ContentSelectionType2 ContentsBTBBank { get; set; }
        public ContentSelectionType2 ContentsBTBAll { get; set; }
        #endregion

        public const int DAYS_ALERT_MEASURE = 3;
        [DataMember]
        public StepInfo[] Steps { get; set; }
        public const int STEP_INDEX_MEASURE = 6;
        public const int STEP_INDEX_HOME = 10;
        public StepInfo Step_Measure
        {
            get
            {
                if (Steps == null || Steps.Length <= STEP_INDEX_MEASURE)
                    return null;
                return Steps[STEP_INDEX_MEASURE];
            }
        }
        public Step_Measurement Step_Measure_Intance
        {
            get
            {
                var step = Step_Measure;
                return step == null ? null : step.Measurement;
            }
        }
        #region Step_Current
        private StepInfo _Step_Current = null;
        public StepInfo Step_Current
        {
            get
            {
                if (_Step_Current == null && Steps.Length > STEP_INDEX_HOME)
                    _Step_Current = Steps[STEP_INDEX_HOME];//tab home
                if (_Step_Current == null && Steps.Length > 0)
                    _Step_Current = Steps[0];
                return _Step_Current;
            }
            set
            {
                if (_Step_Current != value)
                {
                    _Step_Current = value;
                    SendPropertyChanged("Step_Current");
                    SendPropertyChanged("Step_CurrentIndex");
                    if (Steps != null)
                    {
                        foreach (var s in Steps)
                            if (s != null)
                                s.SendPropertyChanged("IsCurrent");
                    }
                }
            }
        }
        public int Step_CurrentIndex
        {
            get
            {
                var current = Step_Current;
                if (Steps != null && current != null)
                {
                    for (int i = 0; i < Steps.Length; i++)
                        if (Steps[i] == current)
                            return i;
                }
                return 0;//thay vi -1
            }
            set
            {
                if (Steps != null &&
                    value >= 0 && value < Steps.Length)
                {
                    Step_Current = Steps[value];
                }
                else
                    Step_Current = null;
                SendPropertyChanged("Step_CurrentIndex");
            }
        }
        #endregion
        public static RootData Intance
        {
            get { return ProjectData.Intance.Period; }
        }

        #region UI
        #region Conclution_Summary_TabHeader_UIText
        [DataMember]
        string _Conclution_Summary_TabHeader_UIText = string.Empty;
        public string Conclution_Summary_TabHeader_UIText
        {
            get
            {
                if (string.IsNullOrEmpty(_Conclution_Summary_TabHeader_UIText))
                    _Conclution_Summary_TabHeader_UIText = "Summary";
                return _Conclution_Summary_TabHeader_UIText;
            }
            set
            {
                if (_Conclution_Summary_TabHeader_UIText != value)
                {
                    _Conclution_Summary_TabHeader_UIText = value;
                    SendPropertyChanged("Conclution_Summary_TabHeader_UIText");
                }
            }
        }
        #endregion
        #region Conclution_Pictures_TabHeader_UIText
        [DataMember]
        string _Conclution_Pictures_TabHeader_UIText = string.Empty;
        public string Conclution_Pictures_TabHeader_UIText
        {
            get
            {
                if (string.IsNullOrEmpty(_Conclution_Pictures_TabHeader_UIText))
                    _Conclution_Pictures_TabHeader_UIText = "Pictures";
                return _Conclution_Pictures_TabHeader_UIText;
            }
            set
            {
                if (_Conclution_Pictures_TabHeader_UIText != value)
                {
                    _Conclution_Pictures_TabHeader_UIText = value;
                    SendPropertyChanged("Conclution_Pictures_TabHeader_UIText");
                }
            }
        }
        #endregion
        #region Conclution_Report_TabHeader_UIText
        [DataMember]
        string _Conclution_Report_TabHeader_UIText = string.Empty;
        public string Conclution_Report_TabHeader_UIText
        {
            get
            {
                if (string.IsNullOrEmpty(_Conclution_Report_TabHeader_UIText))
                    _Conclution_Report_TabHeader_UIText = "Report";
                return _Conclution_Report_TabHeader_UIText;
            }
            set
            {
                if (_Conclution_Report_TabHeader_UIText != value)
                {
                    _Conclution_Report_TabHeader_UIText = value;
                    SendPropertyChanged("Conclution_Report_TabHeader_UIText");
                }
            }
        }
        #endregion
        #endregion

        public static Step_TaskItemGroup[] TaskItemGroups_Source
        {
            get { return RootData.Intance.Steps[3].TaskItemStep.TaskItemGroups_Source.ToArray(); }
        }
        /// <summary>
        /// Dùng de hie thi o Combobox Step 5
        /// </summary>
        public Step_TaskItemGroup[] TaskItemGroupOfStep4
        {
            get
            {
                var data = Intance;
                if (data == null || data.Steps == null || data.Steps.Length < 4)
                    return null;
                var step4 = data.Steps[3];
                return step4.TaskItemStep.TaskItemGroups_Source.ToArray();
            }
        }
        #region  Tab6_Evaluation_Analysis
        public Step_Analysis Tab6_Evaluation_Analysis
        {
            get 
            {
                var data = Intance;
                if (data == null || data.Steps == null || data.Steps.Length < 5)
                    return null;
                var step6 = data.Steps[5];
                return step6.Analysis;
            }
        }
        /// <summary>
        /// Weight Bar Chart
        /// </summary>
        public string Tab6_Evaluation_Analysis_1
        {
            get
            {
                var v = Tab6_Evaluation_Analysis;
                return v == null ? string.Empty : v.Analysis1;
            }
        }
        /// <summary>
        /// Weight Bar Chart Absolute
        /// </summary>
        public string Tab6_Evaluation_Analysis_1_Absolute
        {
            get
            {
                return Tab6_Evaluation_Analysis_1 + " " + ControlTextInfoInData.Intance.eImportanceMode_Absolute_Text;
            }
        }
        /// <summary>
        /// Weight Bar Chart relativ
        /// </summary>
        public string Tab6_Evaluation_Analysis_1_Relativ
        {
            get
            {
                return Tab6_Evaluation_Analysis_1 + " " + ControlTextInfoInData.Intance.eImportanceMode_Relativ_Text;
            }
        }
        /// <summary>
        /// Valuation Bar Chart
        /// </summary>
        public string Tab6_Evaluation_Analysis_2
        {
            get
            {
                var v = Tab6_Evaluation_Analysis;
                return v == null ? string.Empty : v.Analysis2;
            }
        }
        /// <summary>
        /// Portfolio of Potiential
        /// </summary>
        public string Tab6_Evaluation_Analysis_3
        {
            get
            {
                var v = Tab6_Evaluation_Analysis;
                return v == null ? string.Empty : v.Analysis3;
            }
        }
        #endregion

        /// <summary>
        /// Gọi sau khi Intance được gán
        /// </summary>
        public void RaiseAllProperties()
        {
            SendPropertyChanged("TaskItemGroupOfStep4");
        }


        #region Report
        public string Report_STRATEGY_FORMULATION
        {
            get { return Report_BusinessStrategy; }
        }
        public string Report_SucessFactor
        {
            get
            {
                string sDefault = "Success Factor"; ;
                int index = 3;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_SucessFactor_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_SucessFactor;
            }
        }
        public string Report_SucessFactor_FullName//title
        {
            get
            {
                string sDefault = "Success Factor"; ;
                int index = 3;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.FullName;
            }
        }
        public string Report_SucessFactor_Human//title
        {
            get
            {
                int index = 3;
                string sDefault = "Human capital";
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.TaskItemStep == null)
                    return sDefault;
                var check = step.TaskItemStep;
                if (check.TaskItemGroups_Source.Count < 1)
                    return sDefault;
                return check == null ? sDefault : check.TaskItemGroups_Source[0].Name;
            }
        }
        public string Report_SucessFactor_Structural//title
        {
            get
            {
                int index = 3;
                string sDefault = "Structural capital";
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.TaskItemStep == null)
                    return sDefault;
                var check = step.TaskItemStep;
                if (check.TaskItemGroups_Source.Count < 2)
                    return sDefault;
                return check == null ? sDefault : check.TaskItemGroups_Source[1].Name;
            }
        }
        public string Report_SucessFactor_Relational//title
        {
            get
            {
                int index = 3;
                string sDefault = "Relational capital";
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.TaskItemStep == null)
                    return sDefault;
                var check = step.TaskItemStep;
                if (check.TaskItemGroups_Source.Count < 3)
                    return sDefault;
                return check == null ? sDefault : check.TaskItemGroups_Source[2].Name;
            }
        }
        public string Report_SucessFactor_Weighting//title
        {
            get
            {
#warning  can cong them ky tu cho giong tren header ko???
                return ControlTextInfoInData.Intance.TaskItem_WeightText;
            }
        }
        public string Report_SucessFactor_Weighting_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_SucessFactor_Weighting;
            }
        }
        public string Report_BusinessModel
        {
            get
            {
                int index = 0;
                string sDefault = "Business Model"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_BusinessModel_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_BusinessModel;
            }
        }
        public string Report_BusinessStrategy
        {
            get
            {
                int index = 2;
                string sDefault = "Business strategy"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_BusinessStrategy_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_BusinessStrategy;
            }
        }
        public string Report_BusinessStrategy_FullName
        {
            get
            {
                int index = 2;
                string sDefault = "Business strategy"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.FullName;
            }
        }
        public string Report_Review
        {
            get
            {
                int index = 4;
                string sDefault = "Review"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_Review_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_Review;
            }
        }

        public string Report_Review_FullName//Title
        {
            get
            {
                int index = 4;
                string sDefault = "Review"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.FullName;
            }
        }
        public string Report_EVALUATION
        {
            get
            {
                int index = 5;
                string sDefault = "EVALUATION"; ;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_EVALUATION_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_EVALUATION;
            }
        }
        public string Report_EVALUATION_Tab3
        {
            get
            {
                int index = 5;
                string sDefault = "Potentially Portfolio";
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.Analysis == null)
                    return sDefault;
                var check = step.Analysis;
                return check == null ? sDefault : check.Analysis3;
            }
        }
        public string Report_MEASURE
        {
            get
            {
                string sDefault = "MEASURE"; ;
                int index = 6;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_MEASURE_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_MEASURE;
            }
        }
        public string Report_MEASURE_FullName//SubTitle
        {
            get
            {
                string sDefault = "MEASURE"; ;
                int index = 6;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.FullName;
            }
        }
        public int Report_Marketing_Index
        {
            get { return 7; }
        }
        public string Report_Marketing
        {
            get
            {
                string sDefault = "Marketing"; ;
                int index = Report_Marketing_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_Marketing_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_Marketing;
            }
        }
        public string Report_Marketing_FullName//SubTitle
        {
            get
            {
                string sDefault = "MEASURE"; ;
                int index = 7;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.FullName;
            }
        }

        public int Report_Finance_Index
        {
            get { return 9; }
        }
        public string Report_Finance
        {
            get
            {
                string sDefault = "Finance";
#warning hien tab nay dung cuoi. khi chuyen doi can thay lai vi tri index
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_Finance_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_Finance;
            }
        }
        public string Report_Finance_BalancedScoreCards
        {
            get
            {
                string sDefault = "Balanced Score Cards";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.Balance == null)
                    return sDefault;
                return step.BalanceAndOthers.Balance.Step_BalanceAndOthers_Balance_Header;
            }
        }
        public string Report_Finance_InvestmentCalculation
        {
            get
            {
                string sDefault = "Investment Calculation";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.InvestmentCalculation == null)
                    return sDefault;
                return step.BalanceAndOthers.InvestmentCalculation.Step_BalanceAndOthers_InvestmentCalculation_Header;
            }
        }
        public string Report_Finance_PriceCalculation
        {
            get
            {
                string sDefault = "Price Calculation";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.Price == null)
                    return sDefault;
                return step.BalanceAndOthers.Price.Step_BalanceAndOthers_Price_Header;
            }
        }
        public string Report_Finance_TradeCalculation
        {
            get
            {
                string sDefault = "Trade Calculation";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.Trade == null)
                    return sDefault;
                return step.BalanceAndOthers.Trade.Step_BalanceAndOthers_Trade_Header;
            }
        }
        public string Report_Finance_InvestmentPlan
        {
            get
            {
                string sDefault = "Investment Plan";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.InvestmentPlan == null)
                    return sDefault;
                return step.BalanceAndOthers.InvestmentPlan.Step_BalanceAndOthers_InvestmentPlan_Header;
            }
        }
        public string Report_Finance_LiquidityPlan
        {
            get
            {
                string sDefault = "Liquidity Plan";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.LIQUIDITYPLAN == null)
                    return sDefault;
                return step.BalanceAndOthers.LIQUIDITYPLAN.Step_BalanceAndOthers_LIQUIDITYPLAN_Header;
            }
        }
        public string Report_Finance_Profit
        {
            get
            {
                string sDefault = "Profit and Los Statement, Budget";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.PROFIT == null)
                    return sDefault;
                return step.BalanceAndOthers.PROFIT.Step_BalanceAndOthers_PROFIT_LOSS_STATEMENT_Header;
            }
        }

        public string Report_Finance_SheetStatement
        {
            get
            {
                string sDefault = "Sheet Statement";
                int index = Report_Finance_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null || step.BalanceAndOthers == null
                    || step.BalanceAndOthers.SHEET_STATEMENT == null)
                    return sDefault;
                return step.BalanceAndOthers.SHEET_STATEMENT.Step_BalanceAndOthers_Sheet_Statement_Header;
            }
        }
        public int Report_Conclusion_Index
        { get { return 8; } }
        public string Report_Conclusion
        {
            get
            {
                string sDefault = "Conclusion";
#warning hien tab nay dung cuoi. khi chuyen doi can thay lai vi tri index
                int index = Report_Conclusion_Index;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_Conclusion_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_Conclusion;
            }
        }
        public string Report_Conclusion_Image
        {
            get
            {
                string sDefault = "Images";
                if (RootData.Intance != null)
                    return RootData.Intance.Conclution_Pictures_TabHeader_UIText;
                return sDefault;
            }
        }
        public string Report_Conclusion_Report
        {
            get
            {
                string sDefault = "Report";
                if (RootData.Intance != null)
                    return RootData.Intance.Conclution_Report_TabHeader_UIText;
                return sDefault;
            }
        }

        public string Report_BussinessEnvironment
        {
            get
            {
                string sDefault = "Bussiness Environment"; ;
                int index = 1;
                if (this.Steps == null || this.Steps.Length <= index)
                    return sDefault;
                var step = this.Steps[index];
                if (step == null)
                    return sDefault;
                return step.ShortName;
            }
        }
        public string Report_BussinessEnvironment_Comment
        {
            get
            {
                return ControlTextInfoInData.Intance.UI_Comment + " " + Report_BussinessEnvironment;
            }
        }
        public string Report_BussinessEnvironment_MarketSituation_Text
        {
            get
            {
                string sDefault = "Market Situation"; ;
                if (this.Steps == null || this.Steps.Length < 2)
                    return sDefault;
                var step1 = this.Steps[1];
                if (step1 == null || step1.QuestionAnwserStep == null
                    || step1.QuestionAnwserStep.QuestionAnwserGroups_Source == null
                    || step1.QuestionAnwserStep.QuestionAnwserGroups_Source.Count == 0)
                    return sDefault;
                var check = step1.QuestionAnwserStep.QuestionAnwserGroups_Source[0];
                return check == null ? sDefault : check.Name;

            }
        }
        public string Report_BussinessEnvironment_EnvironmentalFactors_Text
        {
            get
            {
                string sDefault = "Environmental Factors"; ;
                if (this.Steps == null || this.Steps.Length < 2)
                    return sDefault;
                var step1 = this.Steps[1];
                if (step1 == null || step1.QuestionAnwserStep == null
                    || step1.QuestionAnwserStep.QuestionAnwserGroups_Source == null
                    || step1.QuestionAnwserStep.QuestionAnwserGroups_Source.Count <= 1)
                    return sDefault;
                var check = step1.QuestionAnwserStep.QuestionAnwserGroups_Source[1];
                return check == null ? sDefault : check.Name;

            }
        }
        public ReportQuestionAnswerItem[] GetReportQuestionAnswerList(int iStep, int iPart)
        {
            List<ReportQuestionAnswerItem> list = new List<ReportQuestionAnswerItem>();
            try
            {
                if (iStep < 0 || iStep >= this.Steps.Length)
                    return list.ToArray();
                var step = this.Steps[iStep];
                if (step == null || step.QuestionAnwserStep == null)
                    return list.ToArray();
                var qas = step.QuestionAnwserStep.QuestionAnwserGroups_Source.ToArray();
                if (iPart < 0 || iPart >= qas.Length)
                    return list.ToArray();
                var qa = qas[iPart];
                if (qa == null)
                    return list.ToArray();
                return qa.QuestionAnswers_Source.Select(c =>
                    new ReportQuestionAnswerItem()
                    {
                        Question = c.Question,
                        Answer = c.Answer
                    }).ToArray();
            }
            catch (Exception exception)
            {
                Log.LogException(exception);
            }
            return list.ToArray();
        }
        public ReportQQSStatementItem[] GetReportQQSStatementList(FactorType eEFType)
        {
            string sCode = string.Empty;
            switch (eEFType)
            {
                case FactorType.BK:
                    sCode = "RC";
                    break;
                case FactorType.HK:
                    sCode = "HC";
                    break;
                case FactorType.SK:
                    sCode = "SC";
                    break;
            }
            var sourve = TaskItemGroupOfStep4.First(c => c.Code == sCode);
            return sourve.Tasks_Source.Select(c => new ReportQQSStatementItem()
            {
                ID = c.ID,
                StatementQl = GetString(c.Quanlity_WeightPercent.ToString() + "% - " + c.Quanlity_Answer),
                StatementQn = GetString(c.Quantity_WeightPercent.ToString() + "% - " + c.Quantity_Answer),
                StatementSy = GetString(c.Systematic_WeightPercent.ToString() + "% - " + c.Systematic_Answer)
            }).ToArray();
        }
        public ReportFactorItem[] GetReportFactorList(FactorType eEFType)
        {
            string sCode = string.Empty;
            switch (eEFType)
            {
                case FactorType.BK:
                    sCode = "RC";
                    break;
                case FactorType.HK:
                    sCode = "HC";
                    break;
                case FactorType.SK:
                    sCode = "SC";
                    break;
            }
            var sourve = TaskItemGroupOfStep4.First(c => c.Code == sCode);
            return sourve.Tasks_Source.Select(c => new ReportFactorItem()
            {
                ID = c.ID,
                FactorName = c.Name,
                Definition = c.Define
            }).ToArray();
        }
        /// <summary>
        /// ID + Weight
        /// </summary>
        /// <param name="eEFType"></param>
        /// <returns></returns>
        public ReportImportanceStatementItem[] GetReportImportanceStatementList(FactorType eEFType)
        {
            string sCode = string.Empty;
            switch (eEFType)
            {
                case FactorType.BK:
                    sCode = "RC";
                    break;
                case FactorType.HK:
                    sCode = "HC";
                    break;
                case FactorType.SK:
                    sCode = "SC";
                    break;
            }
            var sourve = TaskItemGroupOfStep4.First(c => c.Code == sCode);
            return sourve.Tasks_Source.Select(c => new ReportImportanceStatementItem()
            {
                ID = c.ID,
                Statement = c.Weight.ToString()// "-"//todo
            }).ToArray();
        }
        public ReportActionItem[] GetReportActionList()
        {
            if (this.Steps[6] == null)
                return new ReportActionItem[0];
            if (this.Steps[6].Measurement == null)
                return new ReportActionItem[0];
            var measurement = this.Steps[6].Measurement.Measurements_Source;
            if (measurement == null)
                return new ReportActionItem[0];
            return measurement.Select(c => new ReportActionItem
                {
                    Name = this.GetString(c.Name),
                    Effort = this.GetString(c.Expenses),
                    Procedure = this.GetString(c.Procedure),
                    StartDate = (c.StartedDate == BTB_DH.INVALID_DATE) ? "" : c.StartedDate.ToShortDateString(),
                    Result = this.GetString(c.Goal),
                    Benefit = this.GetString(c.ExpectedBenefits),
                    State = c.Status,// this.GetActionStateString(c.State),
                    Duration = (c.Duration == BTB_DH.INVALID_INT) ? "" : c.Duration.ToString()
                }).ToArray();
        }
        private string GetString(string sString)
        {
            if ((sString != null) && (sString.Length > 1))
            {
                while (sString.Substring(sString.Length - 2, 2) == "\r\n")
                {
                    sString = sString.Substring(0, sString.Length - 2);
                }
            }
            return sString;
        }
        #endregion

        private static RootData CreateDefaultRootData()
        {
            RootData data = new RootData();
            data.Steps = new StepInfo[10];

            #region Step 1
            Gen_Step(data);
            #endregion

            #region Step 2
            Gen_Step2(data);
            #endregion

            #region Step 3
            Gen_Step3(data);
            #endregion


            #region Step 4
            Gen_Step4(data);
            #endregion

            #region Step 5
            var step5 = new StepInfo();
            data.Steps[4] = step5;
            step5.ShortName = "Bước 5";
            step5.FullName = "Tên Bước 5";
            step5.Result = StepResult.Create_StepResult_None();
            #endregion

            #region Step 6
            Gen_Step6(data);
            #endregion

            #region Step 7
            Gen_Step7(data);
            #endregion

            #region Step 8
            Gen_Step8(data);
            #endregion

            #region Step 9
            Gen_Step9(data);
            #endregion
            return data;
        }

        private static void Gen_Step8(RootData data)
        {
            var step8 = new StepInfo();
            data.Steps[7] = step8;
            step8.ShortName = "Bước 8";
            step8.FullName = "Tên Bước 8";
            step8.Result = StepResult.Create_StepResult_None();

            var step8_QA_QuestionAnswers = new Step_QuestionAnwser[0];
            Step_QuestionAnwserGroup step8_QA = new Step_QuestionAnwserGroup(step8_QA_QuestionAnswers);
            var QuestionAnwserGroups1 = new Step_QuestionAnwserGroup[] { step8_QA };
            step8.QuestionAnwserStep = new Step_QuestionAnwserStep(QuestionAnwserGroups1);
            step8_QA.Name = "Nhóm câu hỏi";

        }

        private static void Gen_Step7(RootData data)
        {
            var step7 = new StepInfo();
            data.Steps[6] = step7;
            step7.ShortName = "Bước 7";
            step7.FullName = "Tên Bước 7";
            step7.Measurement = new Step_Measurement(null);
            step7.Result = StepResult.Create_StepResult_None();
        }

        private static void Gen_Step6(RootData data)
        {
            var step6 = new StepInfo();
            data.Steps[5] = step6;
            step6.ShortName = "Bước 6";
            step6.FullName = "Tên Bước 6";
            step6.Analysis = new Step_Analysis();
            step6.Analysis.Analysis1 = "Báo cáo 1";
            step6.Analysis.Analysis2 = "Báo cáo 2";
            step6.Analysis.Analysis3 = "Báo cáo 3";
            step6.Result = StepResult.Create_StepResult_None();
        }

        private static void Gen_Step9(RootData data)
        {
            var step9 = new StepInfo();
            data.Steps[8] = step9;
            step9.ShortName = "Bước 9";
            step9.FullName = "Tên Bước 9";
            step9.Result = StepResult.Create_StepResult_None();
        }

        private static void Gen_Step4(RootData data)
        {
            var step4 = new StepInfo();
            data.Steps[3] = step4;
            step4.ShortName = "Bước 4";
            step4.FullName = "Tên Bước 4";
            step4.Result = StepResult.Create_StepResult_None();
            Step_TaskItemGroup step4_Task1 = new Step_TaskItemGroup() { Name = "Con người", Code = "CN" };
            Step_TaskItemGroup step4_Task2 = new Step_TaskItemGroup() { Name = "Vốn", Code = "V" };
            Step_TaskItemGroup step4_Task3 = new Step_TaskItemGroup() { Name = "Mối quan hệ", Code = "MQH" };
            var TaskItemGroups = new Step_TaskItemGroup[] { step4_Task1, step4_Task2, step4_Task3 };
            step4.TaskItemStep = new Step_TaskItemStep(TaskItemGroups);
        }

        private static void Gen_Step3(RootData data)
        {
            var step3 = new StepInfo();
            data.Steps[2] = step3;
            step3.ShortName = "Bước 3";
            step3.FullName = "Tên Bước 3";
            step3.Result = StepResult.Create_StepResult_None();
            var step3_QA_QuestionAnswers = new Step_QuestionAnwser[] { 
            new Step_QuestionAnwser(){ Question ="Câu hỏi 3.1", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 3.2", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 3.3", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 3.4", Answer = "-"}           
            };
            Step_QuestionAnwserGroup step3_QA = new Step_QuestionAnwserGroup(step3_QA_QuestionAnswers);
            var QuestionAnwserGroups3 = new Step_QuestionAnwserGroup[] { step3_QA };
            step3.QuestionAnwserStep = new Step_QuestionAnwserStep(QuestionAnwserGroups3);
            step3_QA.Name = "Nhóm câu hỏi 3";
        }

        private static void Gen_Step2(RootData data)
        {
            var step2 = new StepInfo();
            data.Steps[1] = step2;
            step2.ShortName = "Bước 2";
            step2.FullName = "Tên Bước 2";
            step2.Result = StepResult.Create_StepResult_None();

            #region step2_QA1
            var step2_QA1_QuestionAnswers = new Step_QuestionAnwser[] { 
            new Step_QuestionAnwser(){ Question ="Câu hỏi 2.1-1", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 2.1-2", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 2.1-3", Answer = "-"}          
            };
            Step_QuestionAnwserGroup step2_QA1 = new Step_QuestionAnwserGroup(step2_QA1_QuestionAnswers);
            step2_QA1.Name = "Nhóm câu hỏi 2- 1";
            #endregion
            #region step2_QA2
            var step2_QA2_QuestionAnswers = new Step_QuestionAnwser[] { 
            new Step_QuestionAnwser(){ Question ="Câu hỏi 2.2-1", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 2.2-2", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 2.2-3", Answer = "-"}          
            };
            Step_QuestionAnwserGroup step2_QA2 = new Step_QuestionAnwserGroup(step2_QA2_QuestionAnswers);
            step2_QA2.Name = "Nhóm câu hỏi 2- 2";
            #endregion
            var QuestionAnwserGroups2 = new Step_QuestionAnwserGroup[] { step2_QA1, step2_QA2 };
            step2.QuestionAnwserStep = new Step_QuestionAnwserStep(QuestionAnwserGroups2);
        }

        private static void Gen_Step(RootData data)
        {
            var step1 = new StepInfo();
            data.Steps[0] = step1;
            step1.ShortName = "Bước 1";
            step1.FullName = "Tên Bước 1";
            step1.Result = StepResult.Create_StepResult_None();
            var step1_QA_QuestionAnswers = new Step_QuestionAnwser[] { 
            new Step_QuestionAnwser(){ Question ="Câu hỏi 1", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 2", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 3", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 4", Answer = "-"}
            ,new Step_QuestionAnwser(){ Question ="Câu hỏi 5", Answer = "-"}
            };
            Step_QuestionAnwserGroup step1_QA = new Step_QuestionAnwserGroup(step1_QA_QuestionAnswers);
            var QuestionAnwserGroups1 = new Step_QuestionAnwserGroup[] { step1_QA };
            step1.QuestionAnwserStep = new Step_QuestionAnwserStep(QuestionAnwserGroups1);
            step1_QA.Name = "Nhóm câu hỏi";
        }
    }
    [DataContract]
    public class VMTextBoxFormatInfo : INotifyPropertyChanged
    {
        #region Intance
        public static Action Action_IntanceChanged;
        private static VMTextBoxFormatInfo _Intance = new VMTextBoxFormatInfo();
        public static VMTextBoxFormatInfo Intance
        {
            get
            {
                //if (ProjectData.Intance == null)
                //    return null;
                //if (ProjectData.Intance.VMTextBoxFormatInfo_Intance == null)
                //    ProjectData.Intance.VMTextBoxFormatInfo_Intance = new VMTextBoxFormatInfo();
                //return ProjectData.Intance.VMTextBoxFormatInfo_Intance;
                return _Intance;
            }
            set
            {
                _Intance = value;
                if (Action_IntanceChanged != null)
                    Action_IntanceChanged();
            }
        }
        #endregion
        public VMTextBoxFormatInfo()
        {
            sFontSize = "12";
            FontText = "Arial";
            Color cl = new Color();
            cl.B = 0;
            cl.R = 0;
            cl.G = 0;
            cl.A = 225;
            ForeColor = new SolidColorBrush(cl);
            Background = new SolidColorBrush();
        }

        #region INotifyPropertyChanged Members
        public void SendPropertyChanged(string sProp)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region IsBold
        [DataMember]
        bool _IsBold;
        public bool IsBold
        {
            get
            {
                return _IsBold;
            }
            set
            {
                if (_IsBold != value)
                {
                    _IsBold = value;
                    SendPropertyChanged("IsBold");
                }
            }
        }

        #endregion

        #region IsItalic
        [DataMember]
        bool _IsItalic;
        public bool IsItalic
        {
            get
            {

                return _IsItalic;
            }
            set
            {
                if (_IsItalic != value)
                {
                    _IsItalic = value;
                    SendPropertyChanged("IsItalic");
                }
            }
        }

        #endregion

        #region IsUnder
        [DataMember]
        bool _IsUnder;
        public bool IsUnder
        {
            get
            {
                return _IsUnder;
            }
            set
            {
                if (_IsUnder != value)
                {
                    _IsUnder = value;
                    SendPropertyChanged("IsUnder");
                }
            }
        }
        #endregion

        #region IsCheckSpell
        [DataMember]
        bool _IsCheckSpell;
        public bool IsCheckSpell
        {
            get
            {
                return _IsCheckSpell;
            }
            set
            {
                if (_IsCheckSpell != value)
                {
                    _IsCheckSpell = value;
                    SendPropertyChanged("IsCheckSpell");
                }
            }
        }
        #endregion
        #region sFontSize
        [DataMember]
        string _sFontSize;
        public string sFontSize
        {
            get
            {
                return _sFontSize;
            }
            set
            {
                if (_sFontSize != value)
                {
                    _sFontSize = value;
                    SendPropertyChanged("sFontSize");
                    SendPropertyChanged("dFontSize");
                }
            }
        }
        #endregion

        #region dFontSize
        //string _sFontSize;
        public double dFontSize
        {
            get
            {
                double re = 8;
                if (double.TryParse(sFontSize, out re))
                    re = double.Parse(sFontSize);
                return re;
            }
            set
            {

            }
        }
        #endregion

        #region fontText
        [DataMember]
        string _fontText;
        public string FontText
        {
            get
            {
                return _fontText;
            }
            set
            {
                if (_fontText != value)
                {
                    _fontText = value;
                    SendPropertyChanged("FontText");
                }
            }
        }
        #endregion

        #region Background
        [DataMember]
        long _BacgrounndNumber = 0;
        public Brush Background
        {
            get
            {
                return Convert_UIntBrush(_BacgrounndNumber);

            }
            set
            {
                var newValue = Convert_SolidColorBrushColorToUInt((SolidColorBrush)value);
                if (_BacgrounndNumber != newValue)
                {
                    _BacgrounndNumber = newValue;
                    SendPropertyChanged("Background");

                }
            }
        }
        #region Convert
        private long Convert_ColorToUInt(Color color)
        {
            return (uint)((color.A << 24) | (color.R << 16) |
                          (color.G << 8) | (color.B << 0));
        }
        private long Convert_SolidColorBrushColorToUInt(SolidColorBrush solid)
        {
            var color = solid.Color;
            var colorA = 255;
            return (uint)((colorA << 24) | (color.R << 16) |
                          (color.G << 8) | (color.B << 0));
        }
        private Brush Convert_UIntBrush(long colorNumber)
        {
            return new SolidColorBrush(Convert_UIntColor(colorNumber));
        }
        private Color Convert_UIntColor(long colorNumber)
        {
            byte a, r, g, b;
            a = (byte)((colorNumber & 0xff000000) >> 24);
            r = (byte)((colorNumber & 0x00ff0000) >> 16);
            g = (byte)((colorNumber & 0x0000ff00) >> 8);
            b = (byte)((colorNumber & 0x000000ff));
            return Color.FromArgb(a, r, g, b);
        }
        #endregion
        #endregion

        #region ForeColor
        [DataMember]
        long _ForeColorNumber;

        public Brush ForeColor
        {
            get
            {
                return Convert_UIntBrush(_ForeColorNumber);
            }
            set
            {
                var newValue = Convert_SolidColorBrushColorToUInt((SolidColorBrush)value);
                if (_ForeColorNumber != newValue)
                {
                    _ForeColorNumber = newValue;
                    SendPropertyChanged("ForeColor");

                }

            }
        }
        #endregion
        public void SendProperty_ProjectInfo()
        {
            SendPropertyChanged("FontText");
            SendPropertyChanged("Background");
            SendPropertyChanged("ForeColor");
            SendPropertyChanged("sFontSize");
            SendPropertyChanged("dFontSize");
            SendPropertyChanged("IsUnder");
            SendPropertyChanged("IsItalic");
            SendPropertyChanged("IsBold");
            SendPropertyChanged("IsCheckSpell");
        }
    }
}
